gdk: Unset the DrawingContext <-> cairo_t link on dispose
authorEmmanuele Bassi <ebassi@gnome.org>
Sun, 12 Jun 2016 17:55:34 +0000 (18:55 +0100)
committerEmmanuele Bassi <ebassi@gnome.org>
Sun, 12 Jun 2016 17:55:34 +0000 (18:55 +0100)
When disposing a GdkDrawingContext we should unset the association
between the instance and the Cairo context; this avoids stale pointers
in case a reference that has acquired on the Cairo context survives the
lifetime of the GdkDrawingContext.

gdk/gdkdrawingcontext.c

index c082a155ccb7dbe56cf205e2a413b3c49e82b183..2bf421049532bdc96b923828f04d1ac1a9e9bb60 100644 (file)
@@ -64,6 +64,12 @@ gdk_drawing_context_dispose (GObject *gobject)
 {
   GdkDrawingContext *self = GDK_DRAWING_CONTEXT (gobject);
 
+  /* Unset the drawing context, in case somebody is holding
+   * onto the Cairo context
+   */
+  if (self->cr != NULL)
+    gdk_cairo_set_drawing_context (self->cr, NULL);
+
   g_clear_object (&self->window);
   g_clear_pointer (&self->clip, cairo_region_destroy);
   g_clear_pointer (&self->cr, cairo_destroy);